package NFConnLogging;

require 5;
use Carp;

BEGIN 
{
	use TWM;
	use Data::Dumper;
	use Date::Calc qw(Today Date_to_Days Add_Delta_Days);
	$index = 0;
}


sub new
{
	my $self = {
	};
	return bless $self;
}

sub DESTROY	{
	my $self = shift;
	delete $self->{$_} for (keys %$self);
	undef(%$self);
	undef $self;
}


############################################################
# creates ip key hash with value true/false
############################################################
sub get_blocked
{
	my ($self, $ips) = (shift, shift);
	my $isblocked;
	for (@$ips) 
	{
		$isblocked->{$_->{ip}} = !$_->{enabled};
	}
	$isblocked;
}


sub get_log_filename
{
	my ($day, $month, $year) = (localtime)[3,4,5];
	$month++;
	my $report_file = "logs/".($year+1900).($month>9?$month:"0$month").($day>9?$day:"0$day");
	if (! -e "$ck{twmfolder}/modules/$mc/$report_file")
	{
		toDebugLog("[$$] Create log file:\n$ck{twmfolder}/modules/$mc/$report_file");
		system "echo \"<?xml version='1.0' standalone='yes'?><config></config>\" > $ck{twmfolder}/modules/$mc/$report_file; chmod 666 $ck{twmfolder}/modules/$mc/$report_file;";
	}
	return $report_file;
}

sub get_blocked_list
{
	my $ips = &getIPs;
	my $blockedlist = [];
	for (@$ips)
	{
		push @$blockedlist, 'ip'=>$_->{ip} if (!$_->{enabled});
	}
	return $blockedlist;
}


return 1;
{}
